module.exports = function($scope, $state, $modal, userinfo2, deleteuserinfo, updatemobile,
	updateUserAuthInfo, edituserinfo, updateidcard, syncUserAuthInfo, cleanRedis){


	$scope.typearr =[
	   {
            'label':'手机号',
			'value':'1',
	   },
	   {
           'label':'身份证',
			'value':'2',
	   },
	//    {
    //        'label':'卡号',
	// 		'value':'3',
	//    }
    ];
    $scope.searchform = {'type': '1'};
	$scope.obj = {};
	$scope.userstate = 1;

    $scope.load = function () {
        userinfo2.save($scope.searchform, function(res){
			
         	if(res.errcode !== 0) {
         		alert(res.errmsg);
         		return;
         	}
         	$scope.objs = res.data;
        });
        $scope.userstate = 0;
    };

    $scope.edit = function (obj) {
        var modalInstance = $modal.open({
          template: require('../views/edituserinfo1.html'),
          controller: 'edituserinfo1',
          url:'/edit_userinfo',
          size: 'xs',
          resolve: {
            obj : function(){
                return obj;
            },
            // edituserinfo : function(){
            //     return edituserinfo;
            // },
            // updateidcard : function(){
            //     return updateidcard;
            // },
            // updatemobile : function(){
            //     return updatemobile;
            // }

            
          }
    });

        modalInstance.result.then(function () {
            $scope.load();
        }, function () {

        });

    };

    $scope.clear = function(obj){
    	if (confirm("清除实名制后通过身份证将查询不到票信息，您确认要清除吗？")) {
	    	var para = {
	            userid:obj.userid
	        };
			updateUserAuthInfo.save(para, function(res){

				if(res.errcode === 0)
				{
					alert("清除实名制成功");
					$scope.load();
				}
				else
				{
					alert(res.errmsg);
				}

			});
		}
	}

	$scope.del = function(obj){
    	if (confirm("您确认要删除吗？")) {
	    	var para = {
	            userid:obj.userid,
	            type:1
	        };
			deleteuserinfo.save(para, function(res){

				if(res.errcode === 0)
				{
					alert("删除成功");
					$scope.userstate = 1;
				}
				else
				{
					alert(res.errmsg);
				}

			});
		}
	}

	$scope.forcedel = function(obj){
    	if (confirm("您确认要强制删除吗？")) {
	    	var para = {
	            userid:obj.userid,
	            type:2
	        };
			deleteuserinfo.save(para, function(res){

				if(res.errcode === 0)
				{
					alert("强制删除成功");
					$scope.userstate = 1;
				}
				else
				{
					alert(res.errmsg);
				}

			});
		}
	}

	$scope.synccard = function(obj){
    	if (confirm("您确认要同步卡信息吗？")) {
			syncUserAuthInfo.save({'mobile' : obj.mobile}, function(res){

				if(res.errcode === 0)
				{
					alert("同步成功");
					$scope.load();
				}
				else
				{
					alert(res.errmsg);
				}

			});
		}
	}

	$scope.cleanredis = function(obj){
		if (confirm("您确认要清除缓存吗？")) {
			cleanRedis.save({'mobile' : obj.mobile}, function(res){

				if(res.errcode === 0)
				{
					alert("清除成功");
				}
				else
				{
					alert(res.errmsg);
				}

			});
		}
	}

	$scope.create = function () {
        $state.go('app.createuserinfo');
    };

};